/*
 * signal.c
 *
 * Created: 11.06.2013 21:14:24
 *  Author: Timmo
 */ 

#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include <stdint.h>
#include "settings.h"

void buzzer_init(void){
	PORTD.DIRSET = (1<<PIN4);
	TCD1.CTRLB = TC_WGMODE_FRQ_gc;  //Frequency Generation
	TCD1.CCA = 125; //=> F_CPU/(2*1(CCA+1)) => 4kHz
	TCD1.CTRLA = TC_CLKSEL_DIV4_gc;
	
}


void beep(char nr){

	if(!mt_settings.beep_enable)
		return;


	while(nr--){
		TCD1.CTRLB |= TC1_CCAEN_bm;
		_delay_ms(100);
		TCD1.CTRLB &= ~TC1_CCAEN_bm;
		_delay_ms(100);
	}
	
	
	TCD1.CTRLB &= ~TC1_CCAEN_bm;
	
}

